
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  utility;
import java.util.*;
//import dbmanager.*;

//import java.sql.*;
import java.util.Collections;

import logger.PoolLogger;
public class ItemCodeSequenceGenerator
{
	public static Vector<String> seq = new Vector<String>();
	static int counter = 0;
	PoolLogger pl;
	
	public ItemCodeSequenceGenerator() 
	{	
		if(counter==0)
		{
			createSequence();
			counter++;
		}
		
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}
	public Vector<String> createSequence()
	{
		char [] first = {'A','D','G','J','M','P','T','W','B','E','H','K','N'};
		char [] other={'A','D','G','J','M','P','T','W','B','E','H','K','N','Q','U','X'};
		boolean ChangeSecondChar = false;
		
		for(int i=0;i<first.length-1;i++)
		{
			
			StringBuffer sbr = new StringBuffer();//null
			sbr.append(first[i]);
			System.out.println(sbr.toString());
			for(int j=0;j<other.length;j++)
			{
				int diff1 = first[i]-other[j];
				System.out.println("The diff1 is "+diff1);
				if( diff1 == 0 || diff1 == -1 || diff1 == 1)
				{
					System.out.println(first[i]+" & "+other[j]+" Characters on same button");
					pl.info(first[i]+" & "+other[j]+" Characters on same button");
					pl.debug(first[i]+" & "+other[j]+" Characters on same button");
					pl.warn(first[i]+" & "+other[j]+" Characters on same button");
					pl.fatal(first[i]+" & "+other[j]+" Characters on same button");
					pl.error(first[i]+" & "+other[j]+" Characters on same button");
					pl.trace(first[i]+" & "+other[j]+" Characters on same button");
					continue;
				}
				else
				{	
					if(sbr.length()<=2)
					{
						if(ChangeSecondChar == true)
						{
							String temp = sbr.subSequence(0, 1).toString();
							sbr = new StringBuffer();
							sbr.append(temp);
							sbr.append(other[j]);
							System.out.println(sbr.toString());
						}
						else
						{
							sbr.append(other[j]);
							System.out.println(sbr.toString());
							pl.info(sbr);
							pl.debug(sbr);
							pl.warn(sbr);
							pl.fatal(sbr);
							pl.error(sbr);
							pl.trace(sbr);
						}
					}
					else
					{
						continue;
					}
					for(int k=0;k<other.length;k++)
					{
						int diff2 = other[j]-other[k];
						System.out.println("The diff2 is "+diff2);
						if( diff2 == 0 || diff2 == -1 || diff2 == 1)
						{
							System.out.println(other[j]+" & "+other[k]+" Characters on same button");
							pl.info(other[j]+" & "+other[k]+" Characters on same button");
							pl.debug(other[j]+" & "+other[k]+" Characters on same button");
							pl.warn(other[j]+" & "+other[k]+" Characters on same button");
							pl.fatal(other[j]+" & "+other[k]+" Characters on same button");
							pl.error(other[j]+" & "+other[k]+" Characters on same button");
							pl.trace(other[j]+" & "+other[k]+" Characters on same button");
							continue;
						}
						else
						{	
							if(sbr.length()<3)
							{	
								sbr.append(other[k]);
								System.out.println(sbr.toString());
								seq.add(sbr.toString());
								String temp = sbr.subSequence(0,2).toString();
								sbr = new StringBuffer();
								sbr.append(temp);
								if(other[k]== 'K')
									ChangeSecondChar = true;
								else
									ChangeSecondChar = true;
							}
							else
							{
								continue;
							}
							
						}
					}
				}
			}
			
		}
		System.out.println(seq);
		
		System.out.println("\n"+"After Sorting the Vector !");
		Collections.sort(seq);
		System.out.println(seq);
		pl.info(seq);
		pl.debug(seq);
		pl.warn(seq);
		pl.fatal(seq);
		pl.error(seq);
		pl.trace(seq);
		System.out.println(seq.size());
		return seq;
	}
	public static void main(String args[])
	{
		try
		{
			ItemCodeSequenceGenerator seq = new ItemCodeSequenceGenerator();
			Vector<String> FinalSeq =  seq.createSequence();
			
		/*	String query = "SELECT * FROM categorylist ";
			int i = 0;
			System.out.println("i is "+i);
			ResultSet rs = db.getSelect(query);
			while(rs.next())
			{
				int id = rs.getInt(1);
				System.out.println("The id is "+id);
				
				int varieties = rs.getShort("varieties");
				System.out.println("The varieties is "+varieties);
				
				if(varieties > 0 )
				{
					String subcatQuery = "UPDATE categorylist SET ItemCode = '"+FinalSeq.get(i)+"' WHERE ID ="+id;
					int result = db.getUpdate(subcatQuery);
					if(result > 0)
					{
						System.out.println("Updated");
					}
					else
					{
						System.out.println("Not Updated");
					}
				}
				
				i = i + varieties;
				System.out.println("i is "+i);
			}*/
		} 
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}